Imports KanBan.Pgd.Infrastructure.Exceptions
Imports NHibernate.Criterion
Imports KanBan.Pgd.Domain.Entities
Imports NHibernate

Namespace Repositories

    Public Class GoalDefinitionRepository
        Inherits RepositoryBase(Of GoalDefinition)

        Public Function GetAllByProfileAndArea(ByVal profileId As Guid, ByVal areaId As Guid) As IList(Of GoalDefinition)

            Try

                Dim session As ISession = NHibernateHelper.GetCurrentSession()
                Dim entities As IList(Of GoalDefinition) = New List(Of GoalDefinition)

                entities = session _
                    .CreateCriteria(GetType(GoalDefinition)) _
                    .CreateAlias("Profile", "p") _
                    .CreateAlias("Area", "a") _
                    .Add(Restrictions.Or(Restrictions.Eq("p.Id", profileId), Restrictions.Eq("a.Id", areaId))) _
                    .Add(Restrictions.Eq("IsDeleted", False)) _
                    .List(Of GoalDefinition)()

                Return entities

            Catch ex As Exception

                Throw New TechnicalException(String.Format("Error while trying to 'GetAllByProfile' entities of type = {0} - Details: {1}", _
                                                                            GetType(GoalDefinition).ToString(), ex.Message), ex.InnerException)

            End Try

        End Function

    End Class

End Namespace
